package com.coffee.netty.config;

/**
 * 使用系统属性定义特定配置项的键并提供该配置项的默认值
 * Define the key for a certain config item using system property,
 *   and provide the default value for that config item.
 *
 * @author songkui
 * @since 2024/7/30
 */
public class Configs {
    // ~~~ configs and default values for bootstrap
    /**
     * bootstrap的配置和默认值
     */

    /** TCP_NODELAY option */
    public static final String TCP_NODELAY                           = "coffee.tcp.nodelay";
    public static final String TCP_NODELAY_DEFAULT                   = "true";

    /** TCP SO_REUSEADDR option */
    public static final String TCP_SO_REUSEADDR                      = "coffee.tcp.so.reuseaddr";
    public static final String TCP_SO_REUSEADDR_DEFAULT              = "true";

    /** TCP SO_BACKLOG option */
    public static final String TCP_SO_BACKLOG                        = "coffee.tcp.so.backlog";
    public static final String TCP_SO_BACKLOG_DEFAULT                = "1024";

    /** TCP SO_KEEPALIVE option */
    public static final String TCP_SO_KEEPALIVE                      = "coffee.tcp.so.keepalive";
    public static final String TCP_SO_KEEPALIVE_DEFAULT              = "true";

    /** Netty ioRatio option*/
    public static final String NETTY_IO_RATIO                        = "coffee.netty.io.ratio";
    public static final String NETTY_IO_RATIO_DEFAULT                = "70";

    /** Netty buffer allocator, enabled as default */
    public static final String NETTY_BUFFER_POOLED                   = "coffee.netty.buffer.pooled";
    public static final String NETTY_BUFFER_POOLED_DEFAULT           = "true";

    /** Netty buffer high watermark */
    public static final String NETTY_BUFFER_HIGH_WATERMARK           = "coffee.netty.buffer.high.watermark";
    public static final String NETTY_BUFFER_HIGH_WATERMARK_DEFAULT   = Integer.toString(64 * 1024);

    /** Netty buffer low watermark */
    public static final String NETTY_BUFFER_LOW_WATERMARK            = "coffee.netty.buffer.low.watermark";
    public static final String NETTY_BUFFER_LOW_WATERMARK_DEFAULT    = Integer.toString(32 * 1024);

    /** Netty epoll switch */
    public static final String NETTY_EPOLL_SWITCH                    = "coffee.netty.epoll.switch";
    public static final String NETTY_EPOLL_SWITCH_DEFAULT            = "true";

    /** Netty epoll level trigger enabled */
    public static final String NETTY_EPOLL_LT                        = "coffee.netty.epoll.lt";
    public static final String NETTY_EPOLL_LT_DEFAULT                = "true";

    /** TCP SO_SNDBUF option */
    public static final String TCP_SO_SNDBUF                         = "coffee.tcp.so.sndbuf";
    /** TCP SO_RCVBUF option */
    public static final String TCP_SO_RCVBUF                         = "coffee.tcp.so.rcvbuf";

    // ~~~ configs and default values for idle
    /**
     * 空闲的配置和默认值
     */
    /** TCP idle switch */
    public static final String TCP_IDLE_SWITCH                       = "coffee.tcp.heartbeat.switch";
    public static final String TCP_IDLE_SWITCH_DEFAULT               = "true";

    /** TCP idle interval for client */
    public static final String TCP_IDLE                              = "coffee.tcp.heartbeat.interval";
    public static final String TCP_IDLE_DEFAULT                      = "45";

    /** TCP idle triggered max times if no response*/
    public static final String TCP_IDLE_MAXTIMES                     = "coffee.tcp.heartbeat.maxtimes";
    public static final String TCP_IDLE_MAXTIMES_DEFAULT             = "3";

    /** TCP idle interval for server */
    public static final String TCP_SERVER_IDLE                       = "coffee.tcp.server.idle.interval";
    public static final String TCP_SERVER_IDLE_DEFAULT               = "90";

    // ~~~ configs and default values for connection manager
    /**
     * 连接管理器的配置和默认值
     */

    /** Thread pool min size for the connection manager executor */
    public static final String CONN_CREATE_TP_MIN_SIZE               = "coffee.conn.create.tp.min";
    public static final String CONN_CREATE_TP_MIN_SIZE_DEFAULT       = "3";

    /** Thread pool max size for the connection manager executor */
    public static final String CONN_CREATE_TP_MAX_SIZE               = "coffee.conn.create.tp.max";
    public static final String CONN_CREATE_TP_MAX_SIZE_DEFAULT       = "8";

    /** Thread pool queue size for the connection manager executor */
    public static final String CONN_CREATE_TP_QUEUE_SIZE             = "coffee.conn.create.tp.queue";
    public static final String CONN_CREATE_TP_QUEUE_SIZE_DEFAULT     = "50";

    /** Thread pool keep alive time for the connection manager executor */
    public static final String CONN_CREATE_TP_KEEPALIVE_TIME         = "coffee.conn.create.tp.keepalive";
    public static final String CONN_CREATE_TP_KEEPALIVE_TIME_DEFAULT = "60";

    /** Default connect timeout value, time unit: ms  */
    public static final int    DEFAULT_CONNECT_TIMEOUT               = 1000;

    /** default connection number per url */
    public static final int    DEFAULT_CONN_NUM_PER_URL              = 1;

    /** max connection number of each url */
    public static final int    MAX_CONN_NUM_PER_URL                  = 100 * 10000;

    // ~~~ configs for processor manager
    /**
     * 处理器管理器的配置
     */

    public static final String TP_CPU_SIZE                           = "coffee.cpu.size";
    public static final String TP_CPU_SIZE_DEFAULT                   = "8";

    public static final String EP_CPU_SIZE                           = "coffee.ep.size";
    public static final String EP_CPU_SIZE_DEFAULT                   = "24";

    /**
     * Thread pool min size for the default executor.
     */
    public static final String TP_MIN_SIZE                           = "coffee.tp.min";
    public static final String TP_MIN_SIZE_DEFAULT                   = "60";


    public static final String TSP_MIN_SIZE                           = "coffee.tsp.min";
    public static final String TSP_MIN_SIZE_DEFAULT                   = "80";

    /**
     * Thread pool max size for the default executor.
     */
    public static final String TP_MAX_SIZE                           = "coffee.tp.max";
    public static final String TP_MAX_SIZE_DEFAULT                   = "600";

    /**
     * Thread pool queue size for the default executor.
     */
    public static final String TP_QUEUE_SIZE                         = "coffee.tp.queue";
    public static final String TP_QUEUE_SIZE_DEFAULT                 = "800";

    /**
     * Thread pool keep alive time for the default executor
     */
    public static final String TP_KEEPALIVE_TIME                     = "coffee.tp.keepalive";
    public static final String TP_KEEPALIVE_TIME_DEFAULT             = "60";

    // ~~~ configs and default values for reconnect manager
    /**
     * 重新连接管理器的配置和默认值
     */

    /** Reconnection switch */
    public static final String CONN_RECONNECT_SWITCH                 = "coffee.conn.reconnect.switch";
    public static final String CONN_RECONNECT_SWITCH_DEFAULT         = "false";

    // ~~~ configs and default values for connection monitor
    /**
     * 连接监视器的配置和默认值
     */

    /**
     * Connection monitor switch
     * <p>
     *   If switch on connection monitor, it may cause  to fail.
     *   Please try to use other types of RPC methods
     * </p>
     */
    public static final String CONN_MONITOR_SWITCH                   = "coffee.conn.monitor.switch";
    public static final String CONN_MONITOR_SWITCH_DEFAULT           = "false";

    /** Initial delay to execute schedule task for connection monitor */
    public static final String CONN_MONITOR_INITIAL_DELAY            = "coffee.conn.monitor.initial.delay";
    public static final String CONN_MONITOR_INITIAL_DELAY_DEFAULT    = "10000";

    /** Period of schedule task for connection monitor */
    public static final String CONN_MONITOR_PERIOD                   = "coffee.conn.monitor.period";
    public static final String CONN_MONITOR_PERIOD_DEFAULT           = "180000";

    /** Connection threshold */
    public static final String CONN_THRESHOLD                        = "coffee.conn.threshold";
    public static final String CONN_THRESHOLD_DEFAULT                = "3";

    /** Retry detect period for ScheduledDisconnectStrategy */
    public static final String RETRY_DETECT_PERIOD                   = "coffee.retry.delete.period";
    public static final String RETRY_DETECT_PERIOD_DEFAULT           = "5000";

    /** Connection status */
    public static final String CONN_SERVICE_STATUS                   = "coffee.conn.service.status";
    public static final String CONN_SERVICE_STATUS_OFF               = "off";
    public static final String CONN_SERVICE_STATUS_ON                = "on";

    /** Charset */
    public static final String DEFAULT_CHARSET                       = "UTF-8";
}